<template>
  <el-card class="product-category-container">
    <!-- 分类头部 -->
    <PageTools />
    <!-- 具体分类 -->
    <el-collapse v-model="activeNames" class="category-center" @change="handleChange">
      <el-collapse-item v-for="(obj, index) in category" :key="index" :title="obj.name" :name="index + 1">
        <el-row class="category-row" type="flex">
          <el-col>
            <span class="category-name">{{ obj.children.name }}</span>
          </el-col>
          <el-col class="right">
            <el-button size="mini" type="primary" plain>推荐产品</el-button>
            <el-switch v-model="switchChange" />
            <el-button size="mini" type="primary" plain>推荐产品</el-button>
            <el-button size="mini" type="primary" plain>推荐产品</el-button>
          </el-col>
        </el-row>
      </el-collapse-item>
    </el-collapse>
    <el-dialog title="提示" :visible.sync="dialogShow" width="30%" :before-close="handleClose">
      <el-row type="flex" justify="start">
        <el-col v-for="(item, i) in category.children" :key="i" :span="2">
          <el-image :src="item.imageUrl" fit="cover" style="width: 75px; height: 100px" />
          <span>{{ item.name }}</span>
        </el-col>
      </el-row>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  name: 'ProductCategory',
  data() {
    return {
      activeNames: [],
      category: [
        {
          name: '手机',
          children: [
            {
              name: '小米',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: '苹果',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: '华为',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: 'vivo',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: 'oppo',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: '一加',
              imageUrl: require('@/assets/images/bard.jpeg')
            }
          ]
        },
        {
          name: '运动',
          children: [
            {
              name: '耐克',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: '乔丹',
              imageUrl: require('@/assets/images/bard.jpeg')
            },
            {
              name: '安踏',
              imageUrl: require('@/assets/images/bard.jpeg')
            }
          ]
        }
      ],
      dialogShow: false,
      switchChange: true // 控制开关组件切换
    }
  },
  methods: {
    handleChange(val) {
      console.log(val)
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => { })
    }
  }
}
</script>
<style lang="scss" scoped>
.product-category-container {
  .header {
    ::v-deep .el-card__body {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .refresh {
      border: none;
      background: none;
    }
  }

  .category-center {
    .category-row {
      padding: 0 20px;

      .right {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 400px;

        .el-button--primary.is-plain {
          margin-left: 0;
        }
      }
    }
  }
}</style>
